package controller

import (
	"bluebell-backend/common"
	"bluebell-backend/model/vo"
	"bluebell-backend/service"
	"fmt"
	"github.com/gin-gonic/gin"
	"strconv"
)

func PostVoteController(c *gin.Context) {
	// 参数解析
	p := new(vo.VoteData)
	if err := c.ShouldBindJSON(p); err != nil {
		fmt.Println("参数解析失败")
		common.Error(c, common.ERROR)
		return
	}
	// 拿去uuid
	id, ok := c.Get(common.CtxUserIDKey)
	if !ok {
		common.Error(c, common.CodeNeedLogin)
		return
	}
	// 具体投票业务逻辑
	err := service.VoteForPost(p, strconv.Itoa(int(id.(int64))))
	if err != nil {
		common.ErrorWithMsg(c, common.ERROR, err.Error())
		return
	}
	common.OK(c, common.SUCCESS, nil)
	return
}
